/**
 * 文件名    ： NovelCrawController.java
 * 版权       : XX科技有限公司。
 * 描述       : <描述>
 * 修改时间：2018年11月14日
 * 修改内容：<修改内容>
 */
package com.example.demo.application.controller;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.application.common.MyConstantsRespone;
import com.example.demo.application.common.base.ResultMsgPage;
import com.example.demo.application.model.NovelCrawEntity;
import com.example.demo.application.model.StockKEntity;
import com.example.demo.application.service.IStockService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(description = "股票接口")
@RestController
@EnableAutoConfiguration
@RequestMapping(path = "/stock")
public class StockController {

	protected final Logger log = LoggerFactory.getLogger(StockController.class);

	@Resource(name = "stockService")
	private IStockService stockService;

	@ApiOperation(value = "查询", notes = "查询")
	@RequestMapping(path = "/getList/{stockId}/{length}",method= RequestMethod.GET)
	@ResponseBody
	public ResultMsgPage getList(@PathVariable("stockId") String stockId, @PathVariable("length") int length) throws Exception {
		ResultMsgPage modelMap = new ResultMsgPage();
		StockKEntity form = new StockKEntity();
		form.setStockId(stockId);
		form.setPageSize(length);
		List<StockKEntity> novels = new ArrayList<>();
		novels = stockService.findByParams(form);
		modelMap.setTotalPage(form.getTotlePage());//put("totalPage", form.getTotlePage());
		modelMap.setPageSize(form.getPageSize());//put("pageSize", form.getPageSize());
		modelMap.setCode(MyConstantsRespone.success);//put("code", MyConstantsRespone.success);
		modelMap.setData(novels);//put("data", novels);
		return modelMap;
	}

	/**
	 * <一句话功能简述> 必传参数 <功能详细描述>
	 * 
	 * @param novel
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	private boolean checkEmpty(NovelCrawEntity novel) {
		if (StringUtils.isEmpty(novel.getDestUrl())) {
			return true;
		}
		if (StringUtils.isEmpty(novel.getRule())) {
			return true;
		}
		if (StringUtils.isEmpty(novel.getUserAgent())) {
			return true;
		}
		if (StringUtils.isEmpty(novel.getTitle())) {
			return true;
		}
		if (StringUtils.isEmpty(novel.getUrlNodeTemplet())) {
			return true;
		}
		if (StringUtils.isEmpty(novel.getTitleLab())) {
			return true;
		}
		if (StringUtils.isEmpty(novel.getContentLab())) {
			return true;
		}
		if (StringUtils.isEmpty(novel.getFilePath())) {
			return true;
		}
		return false;
	}
}
